import logging

import allure
import jsonpath

from utils.send_request import send_sql_request


def json_extractor(case,all,res):
    with allure.step("json提取"):
        logging.info(f"json提取,根据{case['json_extractor']}提取数据")
        if case["json_extractor"]:
            for key, value in eval(case["json_extractor"]).items():
                value = jsonpath.jsonpath(res.json(), value)[0]
                all[key] = value
            logging.info(f"json提取,根据{case['json_extractor']}提取数据,此时全局属性all为:{all}")

def sql_extractor(case,all):
    with allure.step("sql提取"):
        logging.info(f"sql提取,根据{case['sql_extractor']}提取数据")
        if case["sql_extractor"]:
            for key, value in eval(case["sql_extractor"]).items():
                value = send_sql_request(value)
                all[key] = value
            logging.info(f"sql提取,根据{case['sql_extractor']}提取数据,此时全局属性all为:{all}")

